import socketserver

class MySocket(socketserver.BaseRequestHandler):
    def handle(self):
        msg = self.request.recv(1024).decode('utf-8')
        print(msg)
        self.request.send(msg.upper().encode('utf-8'))

server = socketserver.TCPServer(('127.0.0.1', 8001), MySocket)
server.serve_forever() # 开启一个永久性的服务




